<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title">导出</h4>
</div>
<form id="export-form" action="/xqc/sales-report/monthly-ajax" method="post" onsubmit="return checkExportForm()">
    <div class="modal-body">
        <div class="row">
            <div class="form-group" style="padding-top: 30px;">
                <label style="padding-top: 3px;text-align: right;" class="col-sm-3 control-label">开始日期<span style="color: red">*</span></label>
                <div class="col-sm-8">
                    <input type="text" id="start_date" name="param[start_date]" placeholder="开始日期">
                </div>
            </div>
            <div class="form-group" style="padding-top: 30px;">
                <label style="padding-top: 3px;text-align: right;" class="col-sm-3 control-label">截止日期<span style="color: red">*</span></label>
                <div class="col-sm-8">
                    <input type="text" id="end_date" name="param[end_date]" placeholder="截止日期">
                </div>
            </div>
            <div class="form-group" style="padding-top: 30px;">
                <label style="padding-top: 3px;text-align: right;" class="col-sm-3 control-label">国家</label>
                <div class="col-sm-8">
                    <select id="country_id" name="param[country_id][]" multiple="multiple">
                        {{ getOptions(\App\Models\Basics\SysCountry::options()) }}
                    </select>
                </div>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        {{ csrf_field() }}
        <input type="hidden" name="action" value="exportByCon">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="submit" class="btn btn-primary" id="export-submit">提交</button>
    </div>
</form>
<script language="JavaScript" type="text/javascript">
    function checkExportForm(){
        var start = $('#start_date').val();
        if(start == ''){
            swal('开始日期不能为空', '', 'error');
            return false;
        }
        var end = $('#end_date').val();
        if(end == ''){
            swal('截止日期不能为空', '', 'error');
            return false;
        }
        var formatStart = new Date(start);
        var formatEnd = new Date(end);
        if(formatStart > formatEnd){
            swal('日期范围有误', '', 'error');
            return false;
        }
        return true;
    }
    $(function () {
        $('#country_id').select2({placeholder: '国家', allowClear: true, width: '147px'});
        $('#start_date').datetimepicker({
            "format":"YYYY-MM",
            "locale":"zh-CN",
            "allowInputToggle":true
        });
        $('#end_date').datetimepicker({
            "format":"YYYY-MM",
            "locale":"zh-CN",
            "allowInputToggle":true
        });
        $('#export-form').ajaxForm(function(data) {
            $("#exModal").modal('hide');
            $(".modal-backdrop").remove();
            $('body').removeClass('modal-open');
            if (typeof data === 'object') {
                if (data.status) {
                    toastr.success(data.message);
                } else {
                    swal(data.message, '', 'error');
                }
            }
        });
    });
</script>
